﻿using CommonEntity.BatteryEntity;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BatteryAPI.Context
{
    public class BatteryContext : DbContext
    {
        public BatteryContext(DbContextOptions<BatteryContext> options)
           : base(options)
        {

        }

        public DbSet<BatteryInfo> BatteryInfos { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            //初始化数据
            modelBuilder.Entity<BatteryInfo>().HasData(new BatteryInfo
            {
                ID = 1,
                Capacity = 2000,
                LastProduceTime = DateTime.Now,
                TotalCount = 10
            },
            new BatteryInfo
            {
                ID = 2,
                Capacity = 3000,
                LastProduceTime = DateTime.Now,
                TotalCount = 10
            },
            new BatteryInfo
            {
                ID = 3,
                Capacity = 4000,
                LastProduceTime = DateTime.Now,
                TotalCount = 10
            },
            new BatteryInfo
            {
                ID = 4,
                Capacity = 4500,
                LastProduceTime = DateTime.Now,
                TotalCount = 10
            });
        }

    }
}
